package com.coocaa.internship.dao.provider;

import com.coocaa.internship.pojo.UserInfo;
import org.springframework.util.StringUtils;

/**
 * @Description:UserInfoSqlProvider
 * @Author: zwh
 * @Date: 2019-07-25
 * @Time: 20:17
 */
public class UserInfoSqlProvider {
    String TABLE_NAME = "user_info";

    public String updateUserInfoById(UserInfo userInfo){
        StringBuilder sql = new StringBuilder("update " + TABLE_NAME + " set ");
        if(!StringUtils.isEmpty(userInfo.getUserInfoAvatar())){
            sql.append("user_info_avatar=#{userInfoAcatar} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoName())){
            sql.append("user_info_name=#{userInfoName} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoEmail())){
            sql.append("user_info_email=#{userInfoEmail} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoPhone())){
            sql.append("user_info_phone=#{userInfoPhone} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoSchool())){
            sql.append("user_info_school=#{userInfoSchool} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoGradtime())){
            sql.append("user_info_gradtime=#{userInfoGradtime} ,");
        }
        if(!StringUtils.isEmpty(userInfo.getUserInfoMajor())){
            sql.append("user_info_major=#{userInfoMajor} ,");
        }
        sql.replace(sql.length() - 1, sql.length(), "");
        return sql.append(" where user_id=#{userId}").toString();
    }
}
